package com.itheima.day05.myInteger.test5;

public class Test {
    public static void main(String[] args) {
        String str = "  91 27 156 4 6 38 50 ";
        str = str.trim();
        // 将字符串转为char类型数组
        char[] arrChar = str.toCharArray();
        // 定义计数器，遍历数组，看有多少个空格
        int count = 0;
        for (int i = 0; i < arrChar.length; i++) {
            if (arrChar[i] == ' ') {
                count++;
            }
        }
        // 通过空格算出数组长度
        int arrLength = count + 1;
        int[] arr = new int[arrLength];
        int count1 = 0;
        int count2 = 0;
        for (int i = 0; i < arrChar.length; i++) {
            if (arrChar[i] == ' ') {
                String strr = "";
                for (int j = count1; j < i; j++) {
                    strr += arrChar[j];
                }
                int arrStr = Integer.parseInt(strr);
                arr[count2] = arrStr;
                count1 = i + 1;
                count2++;
            }else if(i == arrChar.length - 1){
                String strr = "";
                for (int j = count1; j < arrChar.length; j++) {
                    strr += arrChar[j];
                }
                int arrStr = Integer.parseInt(strr);
                arr[count2] = arrStr;
            }
        }

        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
    }
}
